package com.example.thymeleaf_study.controller;


import com.example.thymeleaf_study.Vo.ResultVo;
import com.example.thymeleaf_study.entity.UserInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/exception")
    @RestController
    public class ExceptionController {

        @GetMapping("/test1")
        public ResultVo test1() {
            UserInfo userInfo = null;
            userInfo.setUsername("zhangsan");
            return new ResultVo(200,"成功",userInfo);
        }

        @GetMapping("/test2")
        public ResultVo test2() {
            int[] arr= {1,2,3};
            System.out.println(arr[3]);//发生越界针异常
            //以下是正常业务代码 省略


            return new ResultVo(200,"成功",arr);
        }

        @GetMapping("/test3")
        public ResultVo test3() {
            int i=10/0; //发生算术异常
            //以下是正常业务代码
            return new ResultVo(200,"成功",i);
        }
    }
